import { setProfileOdds } from '@/api/profile'
// import { setOdds } from '@/api/socket'
import { useAccountStore, useBettingConfigStore } from '@/store'
import { Odds } from '@/enums'

export const changeOdds = (odds: Odds) => {
	const accountStore = useAccountStore()
	// setOdds(odds)
	if (accountStore.isLogin) {
		try {
			setProfileOdds({ odds }).then()
		} catch (error) {}
	}
}

export const getOddsCode = (odds: Odds) => {
	switch (odds) {
		case Odds.decimal:
			return 'DEC'
		case Odds.hk:
			return 'HK'
		case Odds.indo:
			return 'ID'
		case Odds.malay:
			return 'MY'
	}
}

export const getComboOddsByList = (oddsList: any[] | undefined) => {
	let res = 0
	if (oddsList) {
		const bettingConfigStore = useBettingConfigStore()
		let comboHasLowOdds = false
		oddsList.forEach((item) => {
			if (!res) {
				res = 1
			}
			res *= item
			if (item < bettingConfigStore.comboBonusMinTrueOdds) {
				comboHasLowOdds = true
			}
		})
		if (!comboHasLowOdds && res) {
			const comboBonus = bettingConfigStore.comboBonus
			for (let index = comboBonus.length - 1; index >= 0; index--) {
				const { number, percent } = comboBonus[index]
				if (oddsList.length >= number) {
					return res + (res * parseFloat(percent)) / 100
				}
			}
		}
	}
	return res
}
